package com.focusai.efairy.ui.adapter.project;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.focusai.efairy.R;
import com.focusai.efairy.model.response.ProjectManageResponse;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by luo_guangwen on 2017/9/8.
 */

public class ProjectManagerDevItemTypeViewBinder extends ItemViewBinder<ProjectManageResponse.DevItem, ProjectManagerDevItemTypeViewBinder.ViewHolder> {

    private Context mContext;
    private OnItemClickListener onItemClickListener;
    public ProjectManagerDevItemTypeViewBinder(Context mContext) {
        this.mContext = mContext;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_project_manager_items, parent, false);
        return  new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull final ProjectManageResponse.DevItem dataItem) {
        holder.lableText.setText(dataItem.efairydevice_name);
        holder.valueText.setText(dataItem.efairydevice_id + "");
        if (onItemClickListener != null){
            holder.llayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClick(dataItem);
                }
            });
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView lableText;
        TextView valueText;
        LinearLayout llayout;
        ViewHolder(View itemView) {
            super(itemView);
            lableText = (TextView) itemView.findViewById(R.id.ll_project_lable);
            valueText = (TextView) itemView.findViewById(R.id.text_project_value);
            llayout = (LinearLayout) itemView.findViewById(R.id.ll_project_item);
        }
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener{
        void onItemClick(ProjectManageResponse.DevItem item);
    }
}
